unit NewMap;

interface

uses
  Database,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons;

type
  TFormNewMap = class(TForm)
    BtnOK: TBitBtn;
    BtnCancel: TBitBtn;
    EditMap: TEdit;
    EditMemo: TMemo;
    label2: TLabel;
    Label1: TLabel;
    procedure EditMapChange(Sender: TObject);
    procedure EditMapKeyPress(Sender: TObject; var Key: Char);
    procedure BtnCancelClick(Sender: TObject);
    procedure BtnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    didcreate: boolean;
    mapname: string;
  end;

var
  FormNewMap: TFormNewMap;

implementation

uses Map, DBClient;

{$R *.DFM}

procedure TFormNewMap.FormCreate(Sender: TObject);
begin
  didcreate:=false;
end;

procedure TFormNewMap.BtnCancelClick(Sender: TObject);
begin
  close;
end;

procedure TFormNewMap.EditMapChange(Sender: TObject);
begin
  if length(EditMap.text) > 0 then BtnOK.enabled:=true
  else BtnOK.enabled:=false;
end;

procedure TFormNewMap.EditMapKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then begin
    EditMemo.setfocus;
    key:=#0;
  end;
end;

procedure TFormNewMap.BtnOKClick(Sender: TObject);
var
  table: TClientDataset;
begin
  if EditMap.text = '' then begin
    messagedlg('Please enter a map level name',mtinformation,[mbok],0);
    EditMap.setfocus;
    exit;
  end;
  if pos('"',EditMap.text) > 0 then begin
    messagedlg('Map level names cannot contain quotes',mtinformation,[mbok],0);
    EditMap.selectall;
    EditMap.setfocus;
    exit;
  end;
  if Datawell.IsMap(EditMap.text) then begin
    messagedlg('A map level of that name already exists',mtinformation,[mbok],0);
    EditMap.selectall;
    EditMap.setfocus;
    exit;
  end;
  table:=TClientDataset.create(self);
  with table do begin
    CloneCursor(Datawell.TableMaps, true);
    active:=true;
    append;
    FieldByName('map_id').AsInteger := FormMap.GetNewID;
    fieldbyname('Map').asstring:=EditMap.text;
    fieldbyname('Zoom').asinteger:=150;
    fieldbyname('ShowGrid').asboolean:=true;
    fieldbyname('ShowLabels').asboolean:=true;
    fieldbyname('ShowTags').asboolean:=true;
    fieldbyname('ShowShadows').asboolean:=false;
    fieldbyname('ShowStubs').asboolean:=true;
    fieldbyname('LL').asboolean:=false;
    fieldbyname('Memo').assign(EditMemo.lines);
    fieldbyname('HomeX').asinteger:=
      -((FormMap.width-50)*5) div 300;
    fieldbyname('HomeY').asinteger:=
      ((FormMap.height-100)*5) div 300;
    fieldbyname('SpeedEdit').asboolean:=true;
    fieldbyname('FColor').asinteger:=clsilver;
    fieldbyname('BColor').asinteger:=clwhite;
    fieldbyname('LColor').asinteger:=clblack;
    fieldbyname('SColor').asinteger:=clblack;
    fieldbyname('S1').asstring:='Arial';
    fieldbyname('S2').asstring:='';
    fieldbyname('S3').asstring:='';
    fieldbyname('S4').asstring:='';
    fieldbyname('S5').asstring:='';
    fieldbyname('I1').asinteger:=360;
    fieldbyname('I2').asinteger:=clsilver;
    fieldbyname('I3').asinteger:=clteal;
    fieldbyname('I4').asinteger:=clblack;
    fieldbyname('I5').asinteger:=0;
    fieldbyname('L1').asboolean:=false;
    fieldbyname('L2').asboolean:=false;
    fieldbyname('L3').asboolean:=true;
    fieldbyname('L4').asboolean:=true;
    fieldbyname('L5').asboolean:=true;
    post;
  end;
  table.free;
  datawell.TableMaps.ApplyUpdates(0);
  didcreate:=true;
  mapname:=EditMap.text;
  close;
end;

end.
